package at.fhj.app.util;

import at.fhj.app.retriever.FHPIRetriever;

/**
 * Helper class responsible for making the C2DM specific requests to the FHPI
 * service.
 * 
 * @author Michael Mitteregger <michael.mitteregger.itm09@fh-joanneum.at>
 */
public class C2DMRequestHandler {
    private static final String REGISTER_URL = "registerC2DM.php";

    FHPIRetriever retriever;

    public C2DMRequestHandler() {
	retriever = new FHPIRetriever();
    }

    /**
     * Makes the request to register the client.
     */
    public String registerClientRequest(String clientId) {
	String url = REGISTER_URL;
	String[] argNames = new String[] { "mode", "id" };
	String[] argValues = new String[] { "R", clientId };

	retriever.prepareRequest(url, argNames, argValues);
	return retriever.retrieve();
    }

    /**
     * Makes the request to UNregister the client.
     */
    public String unregisterClientRequest(String clientId) {
	String url = REGISTER_URL;
	String[] argNames = new String[] { "mode", "id" };
	String[] argValues = new String[] { "U", clientId };

	retriever.prepareRequest(url, argNames, argValues);
	return retriever.retrieve();
    }
}
